package com.example.error;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.Map;

//处理异常
//全局捕获宜昌 使用AOP 技术 采用通知

@ControllerAdvice(basePackages ={ "com.example.qianwen.controller","com.example.love.controller"})  //康戳了   饿的饭死
public class GIobalExceptionHandler {

   // ModelAndView   返回视图页面
    @ExceptionHandler(RuntimeException.class)
    @ResponseBody //返回json
    public Map<String,Object> errorResult(){
        Map<String,Object> errorResultMap = new HashMap<String,Object>();
        errorResultMap.put("errorCode", "500");
        errorResultMap.put("errorMag", "系统错误");
        return  errorResultMap;
    }
}
